package com.soft.service;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.soft.entity.Money;
import com.soft.entity.Operator;
import com.soft.mapper.MoneyMapper;
import com.soft.mapper.OperatorMapper;

@Service
public class OperatorService {
@Autowired
private OperatorMapper operatorMapper;
@Autowired
private MoneyMapper moneyMapper;
public List<Operator> queryByMoneyId(Long moneyId){
	QueryWrapper<Money> moneyWrapper = new QueryWrapper<>();
    moneyWrapper.eq("money_id", moneyId);
    Money money = moneyMapper.selectOne(moneyWrapper);
	QueryWrapper<Operator> operatorWrapper = new QueryWrapper<>();
    operatorWrapper.eq("money_id", moneyId);
    List<Operator> operatorList = operatorMapper.selectList(operatorWrapper);
    return operatorList;
}
public int insertOperator(Long opid,String opname,BigDecimal moincome) {
	QueryWrapper<Money> moneyWrapper = new QueryWrapper<>();
	moneyWrapper.eq("money_income", moincome);
	Money money = moneyMapper.selectOne(moneyWrapper);
	Operator operator = new Operator();
	operator.setId(opid);
	operator.setOperatorname(opname);
	operator.setMoneyid(money.getId());
	int num = operatorMapper.insert(operator);
	return num;
}
public int updateOperator(Long opid,String opname,BigDecimal moincome) {
	QueryWrapper<Money> moneyWrapper = new QueryWrapper<>();
	moneyWrapper.eq("money_income", moincome);
	Money money = moneyMapper.selectOne(moneyWrapper);
	UpdateWrapper<Operator> operatorWrapper = new UpdateWrapper<>();
	operatorWrapper.eq("operator_id", opid);
	operatorWrapper.eq("money_id", money.getId());
	Operator operator = new Operator();
	operator.setOperatorname(opname);
	int num = operatorMapper.update(operator,operatorWrapper);
	return num;
}
}
